﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace Login
{
    public class LoginNotice : Fsm.FsmStateMonoBase<Login.LoginState>
    {
        LoginManager manager
        {
            get
            {
                return this.controller as LoginManager;
            }
        }

        public LoginNotice(LoginState state, LoginManager ctrl):base(state, ctrl)
        {

        }

        public override void Enter()
        {
            if (!string.IsNullOrEmpty(GameConfig.Instance.announceUrl))
            {
                ShowAnnouncePage();
            }
            else
            {
                manager.SwitchState(LoginState.LoginAuth);
            }
        }

        void ShowAnnouncePage()
        {
            GameObject sysNotice = GameObject.Instantiate(Resources.Load("Pages/SystemAnnouncePage")) as GameObject;
            sysNotice.transform.parent = UIAutoSize.Instance.transform;
            sysNotice.transform.localScale = Vector3.one;
            sysNotice.transform.localPosition = new Vector3(0, 10, 0);
            var scirpt = sysNotice.GetComponent<SystemAnnouncePage>();
            scirpt.SetOnClose(OnAnnouncePageClose);
            scirpt.noticeUrl = GameConfig.Instance.announceUrl;
            scirpt.ShowNotice();

        }

        void OnAnnouncePageClose()
        {
            manager.SwitchState(LoginState.LoginAuth);
        }

    }
}
